﻿@{
    ViewBag.Title = "Xemgiohang";
    Layout = "~/Views/Shared/_LayoutWebmini.cshtml";
    var sl = (List<int>)ViewBag.soluong;
    var lstdn = (List<Model.Object.SanPham>)ViewBag.dssanphamdn;
    int tongthanhtoan = 0;
}

@if (sl.Count == 0)
{
   @Html.Action("Giotrong", "ViewHelper")
}
else
{

<div class="col-main">
    <div class="cart">
        <div class="page-title title-buttons">
            <h1>Giỏ hàng</h1>
            <ul class="checkout-types">
                <li>
                    <a href="@Url.Action("Thanhtoan","Home") "><button type="button" title="Đặt mua" class="button btn-proceed-checkout btn-checkout"><span><span>Đặt mua</span></span></button></a>
                </li>
            </ul>
        </div>
        <form method="post">
            <fieldset>
                <table id="shopping-cart-table" class="data-table cart-table">
                    <colgroup>
                        <col width="1">
                        <col>
                        <col width="1">
                        <col width="1">
                        <col width="1">
                        <col width="1">
                        <col width="1">
                    </colgroup>
                    <thead>
                        <tr class="first last">
                            <th class="td-image" rowspan="1">&nbsp;</th>
                            <th class="td-name" rowspan="1"><span class="nobr">Tên sản phẩm</span></th>
                            <th class="td-edit" rowspan="1"></th>
                            <th class="td-price" colspan="1"><span class="nobr">Đơn giá</span></th>
                            <th class="td-qty" rowspan="1">Số lượng</th>
                            <th class="td-price" colspan="1">Tổng tiền</th>
                            <th class="td-delete" rowspan="1">&nbsp;</th>
                        </tr>
                    </thead>
                    <tfoot>
                        <tr class="first last">
                            <td colspan="50" class="a-right last">
                                <button type="button" title="Tiếp tục mua sắm" class="button button_white btn-continue" onclick=""><span><span>Tiếp tục mua sắm</span></span></button>
                                <button type="submit" title="Cập nhật giỏ hàng" class="button button_white btn-update"><span><span>Cập nhật giỏ hàng</span></span></button>
                            </td>
                        </tr>
                    </tfoot>
                    <tbody>
                        @for (int i = 0; i < lstdn.Count; i++)
                        {
                            <tr>
                                <td class="td-image"><a href="@Url.Action("XemChiTietSanPham", "Home", new
                                                         {
                                                             id = lstdn[i].ID,
                                                             loaisp = Nongsan.StringUils.UrlRewrite(lstdn[i].LoaiSanPham.Ten_Loai),
                                                             tensp = Nongsan
                                                                 .StringUils.UrlRewrite(lstdn[i].Ten)
                                                         })" title=@lstdn[i].Ten class="product-image">
                                    <img src=@lstdn[i].HinhAnhs.FirstOrDefault().ImagePath data-srcx2=@lstdn[i].HinhAnhs.FirstOrDefault().ImagePath width="200" height="200" alt=@lstdn[i].Ten></a></td>
                                <td class="td-name">
                                    <h2 class="product-name">
                                        <a href="@Url.Action("XemChiTietSanPham", "Home", new
                                            {
                                                id = lstdn[i].ID,
                                                loaisp = Nongsan.StringUils.UrlRewrite(lstdn[i].LoaiSanPham.Ten_Loai),
                                                tensp = Nongsan
                                                    .StringUils.UrlRewrite(lstdn[i].Ten)
                                            })">@lstdn[i].Ten</a>
                                    </h2>
                                </td>
                                <td class="a-center td-edit">
                                    <a href="#" title="Edit item parameters">Thay đổi</a>
                                </td>


                                <td class="a-center td-price">
                                    <span class="td-title">Đơn giá</span>
                                    <span class="cart-price">
                                        <span class="price">@lstdn[i].Gia đ</span>
                                    </span>


                                </td>
                                <td class="a-center td-qty">
                                    <span class="td-title">Số lượng</span>
                                    <input id="txtqty_@lstdn[i].ID" name="txtqty_@lstdn[i].ID" value=@sl[i] size="4" title="Số lượng" class="input-text qty" maxlength="12" onblur="javascript: getspwithqty(@lstdn[i].ID);">
                                </td>
                                <td class="a-center td-price">
                                    <span class="td-title">Tổng tiền</span>
                                    <span class="cart-price">
                                        <div style="display: none">@(tongthanhtoan += lstdn[i].Gia * sl[i])</div>
                                        <span class="price">@(lstdn[i].Gia * sl[i]) đ</span>
                                    </span>
                                </td>
                                <td class="a-center td-delete last"><a onclick="javascript: xoasp(@lstdn[i].ID);"  title="Gỡ bỏ item" class="btn-remove btn-remove2">Gỡ bỏ item</a>
                                    <span class="td-actions"><a class="btn-edit btn-edit2"  href="@Url.Action("Xemgiohang", "Home")" title="Edit item parameters">Thay đổi</a></span>
                                    <span class="td-actions"><a class="btn-remove btn-remove2" title="Gỡ bỏ item">Gỡ bỏ item</a></span>
                                </td>
                            </tr>
                        }

                    </tbody>
                </table>
                <script type="text/javascript">decorateTable('shopping-cart-table')</script>
            </fieldset>
        </form>
        <div class="cart-collaterals row clearfix">
            <!--<div class="grid_4">
            <img src="" />
        </div> -->
            <div class="grid_4">
                <div class="cart-block cart-coupon">
                    <form id="discount-coupon-form" action="http://www.nongsanngon.com.vn/checkout/cart/couponPost/" method="post">
                        <div class="discount">
                            <h2>Mã giảm giá</h2>
                            <div class="discount-form">
                                <label for="coupon_code">Nhập mã giảm giá của bạn nếu có.</label>
                                <input type="hidden" name="remove" id="remove-coupone" value="0">
                                <div class="input-box">
                                    <input class="input-text" id="coupon_code" name="coupon_code" value="">
                                </div>
                                <div class="buttons-set">
                                    <button type="button" title="Kiểm tra mã giảm giá" class="button" onclick="discountForm.submit(false)" value="Kiểm tra mã giảm giá"><span><span>Kiểm tra mã giảm giá</span></span></button>
                                </div>
                            </div>
                        </div>
                    </form>
                    <script type="text/javascript">
                        //<![CDATA[
                        var discountForm = new VarienForm('discount-coupon-form');
                        discountForm.submit = function (isRemove) {
                            if (isRemove) {
                                $('coupon_code').removeClassName('required-entry');
                                $('remove-coupone').value = "1";
                            } else {
                                $('coupon_code').addClassName('required-entry');
                                $('remove-coupone').value = "0";
                            }
                            return VarienForm.prototype.submit.bind(discountForm)();
                        }
                        //]]>
                    </script>
                </div>
            </div>
            <div class="grid_4">
                <div class="cart-block cart-total">
                    <table id="shopping-cart-totals-table">
                        <colgroup>
                            <col>
                            <col width="1">
                        </colgroup>
                        <tfoot>
                            <tr>
                                <td style="" class="a-right" colspan="1">
                                    <strong>Tổng thanh toán</strong>
                                </td>
                                <td style="" class="a-right">
                                    <strong><span class="price">@tongthanhtoan đ</span></strong>
                                </td>
                            </tr>
                        </tfoot>
                        <tbody>
                            <tr>
                                <td style="" class="a-right" colspan="1">Tổng tiền    </td>
                                <td style="" class="a-right">
                                    <span class="price">@tongthanhtoan đ</span>    </td>
                            </tr>
                        </tbody>
                    </table>
                    <ul class="checkout-types">
                        <li>
                            <a href="@Url.Action("Thanhtoan","Home")"><button type="button" title="Đặt mua" class="button btn-proceed-checkout btn-checkout")"><span><span>Đặt mua</span></span></button></a>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
        <!-- SLIDER BOF -->
        <!-- SLIDER EOF -->
    </div>
</div>
}